import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

// add the following dependencies
import Components from 'unplugin-vue-components/vite';
import {
  ElementPlusResolver,
  AntDesignVueResolver
} from 'unplugin-vue-components/resolvers'
import { AntDesignXVueResolver } from 'ant-design-x-vue/resolver';

// https://vite.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
      '@components': path.resolve(__dirname, './src/components'),
      '@views': path.resolve(__dirname, './src/views'),
      '@store': path.resolve(__dirname, './src/store'),
    },
  },
  plugins: [
    vue(),
    Components({
      // 自动扫描的目录，默认是 src/components
      dirs: ['src/components'],
      extensions: ['vue', 'tsx', 'ts'], // 支持的文件后缀
      // 是否生成 d.ts 类型声明，提升TS体验
      dts: 'src/components.d.ts',
      // ui库解析器
      resolvers: [
        ElementPlusResolver({ importStyle: true, resolveIcons: true }),
        AntDesignVueResolver({ importStyle: true, resolveIcons: true }),
        AntDesignXVueResolver({ importStyle: true, resolveIcons: true })
      ],
      // 允许在模板中直接使用组件
      include: [/\.vue$/, /\.vue\?vue/, /\.tsx$/],
    })
  ],
})
